﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yunwei.DAL;
using Yunwei.Domain.Models;
using Yunwei.IBizLogic;

namespace Yunwei.BizLogic
{
    public class VendorCustomerService : BaseService<VendorCustomer>, IVendorCustomerService
    {
        public VendorCustomerService()
            : base(RepositoryFactory.VendorCustomerRepository)
        {

        }

        public IQueryable<VendorCustomer> FindList(int number, int vendor_Id, int orderCode)
        {
            return FindPageList(out number, 1, number, vendor_Id, orderCode);
        }

        public IQueryable<VendorCustomer> FindPageList(out int totalRecord, int pageIndex, int pageSize, int vendor_Id, int order)
        {
            IQueryable<VendorCustomer> _commonModels = CurrentRepository.Entities;
            if (vendor_Id > 0) _commonModels = _commonModels.Where(vi => vi.Vendor_Id == vendor_Id);

            _commonModels = Order(_commonModels, 1);
            totalRecord = _commonModels.Count();
            return PageList(_commonModels, pageIndex, pageSize).AsQueryable();
        }

        public IQueryable<VendorCustomer> Order(IQueryable<VendorCustomer> entitys, int orderCode)
        {
            switch (orderCode)
            {
                //默认排序
                default:
                    entitys = entitys.OrderByDescending(cm => cm.Restaurant_Id);
                    break;
            }
            return entitys;
        }
    }
}
